from socket import *
from threading import Thread
def recv_data():
    while True:
        redata=s.recvfrom(1024) #1024表示本次接收的最大字节数
        print(redata)
        recv_content=redata[0].decode('gbk')
        print(f"收到的远程信息：{recv_content},from{redata[1]}")
        if recv_content=='888':
            print('结束聊天！')
            break

def send_data():
    addr=("127.0.0.1",6666)
    while True:
        data=input('请输入：')
        s.sendto(data.encode('gbk'),addr)
        if data=='888':
            print('结束聊天！')
            break

if __name__=='__main__':
    s=socket(AF_INET,SOCK_DGRAM)
    s.bind(('127.0.0.1',9999))
    #创建两个线程
    t1 = Thread(target=recv_data)
    t2=Thread(target=send_data)
    t1.start()
    t2.start()
    t1.join()
    t2.join()